package com.api.oa.mapper;

import com.api.oa.model.entity.FileList;
import com.api.oa.model.vo.FileVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface FileListMapper {


    @Insert("insert into aoa_file_list (" +
            "fileName," +
            "filePath," +
            "size," +
            "contentType," +
            "uploadTime," +
            "fileShuffix," +
            "fileIstrash," +
            "fileIsshare," +
            "fileUserId," +
            "fileClassify" +
            ") " +
            "values " +
            "(" +
            "#{business.fileName}," +
            "#{business.filePath}," +
            "#{business.size}," +
            "#{business.contentType}," +
            "#{business.uploadTime}," +
            "#{business.fileShuffix}," +
            "#{business.fileIstrash}," +
            "#{business.fileIsshare}," +
            "#{business.fileUserId}," +
            "#{business.fileClassify}" +
            ")")

    @Options(useGeneratedKeys = true, keyProperty = "fileId", keyColumn = "id")
    int insert(@Param("business") FileList business);


    @Update("update aoa_file_list set fileName = #{org.fileName}, " +
            "filePath=#{org.filePath}," +
            "size = #{org.size} , " +
            "contentType= #{org.contentType}," +
            "uploadTime=#{org.uploadTime}," +
            "fileShuffix=#{org.fileShuffix}," +
            "fileIstrash=#{org.fileIstrash} ," +
            "fileIsshare =#{org.fileIsshare} , " +
            "fileUserId=#{org.fileUserId}," +
            "fileClassify = #{org.fileClassify} where fileId = #{org.fileId}")
    int update(@Param("org") FileList org);


    @Delete("delete from aoa_file_list where fileId=#{id}")
    void delete(@Param("id") Long id);




    @Select("<script> select aoa_file_list.*,yq_user.uname as RealName from aoa_file_list left join yq_user on aoa_file_list.fileUserId = yq_user.userId " +
            "where 1=1 " +
            "<if test='classifyId != null'> and fileClassify = #{classifyId}  </if> " +
            "<if test='keyWord != null'> and fileName like concat('%', #{keyWord},'%')  </if> " +
            "<if test='userId != null || userId !=\"\"'> and fileUserId = #{userId} </if> order by uploadTime desc</script>")
    List<FileVO> list(@Param("classifyId") Long classify, @Param("userId") String userId,@Param("keyWord") String keyWord);


    @Select("select * from aoa_file_list where fileId = #{id} limit 1")
    FileList findOne(@Param("id") Long id);


}
